﻿#include"XQHttpReplyObject.h"
#include"XQHttpObject.h"
QEvent HttpResponseEvent()
{
	return QEvent(QEvent::User);
}
XQHttpReplyObject::XQHttpReplyObject(QObject* parent) :QObject(parent) {};

QByteArray XQHttpReplyObject::appName() const
{
	return name().toUtf8();
}

QString XQHttpReplyObject::name()const
{
	return *m_pName;
};
void XQHttpReplyObject::setName(const QString& name)
{
	m_name = name;
}
void XQHttpReplyObject::bindName(QString* name)
{
	if (name)
		m_pName = name;
	else
		m_pName = &m_name;
}
void XQHttpReplyObject::bindDir(QString* dir)
{
	m_dir = dir;
}
QString XQHttpReplyObject::dir() const
{
	if (m_dir)
		return *m_dir;
	return QString();
}
QString XQHttpReplyObject::path(const QString& p) const
{
	auto P = p;
	P=P.replace("\\", "/").trimmed();
	auto C = dir().replace("\\","/").trimmed();
	if (P.isEmpty()||C.isEmpty())
		return C;
	if (C.back() != '/' && P.front() != '/')
		C += '/';
	else if (C.back() == '/' && P.front() == '/')
		C.remove(C.size()-1, 1);
	C += P;
	return C;
}
bool XQHttpReplyObject::isAccepted(XQHttpHeadObject* head) const
{
	return true;
}
XQHttpHeadReply XQHttpReplyObject::reply(QIODevice* socket, XQHttpHeadRequest* header)
{		
	return XQHttpHeadReply();
};

void XQHttpReplyObject::buffer(QIODevice* socket, XQHttpHeadObject* head, const QByteArray& buffer)
{
	XQHttpObject::defaultBuffFunc(socket,head,buffer);
}

void XQHttpReplyObject::clientConnected(QIODevice* socket)
{
}

void XQHttpReplyObject::clientdisconnected(QIODevice* socket)
{
}

